package io.github.biezhi.factory.methodFactory;

/**
 * 2. 工厂方法模式
 * 工厂方法模式定义一个创建对象的接口，但让子类决定实例化哪一个类。工厂方法使得一个类的实例化延迟到其子类
 */
interface Shape {
    void draw();
}

class Circle implements Shape {
    @Override
    public void draw()
    {
        System.out.println("Inside Circle::draw() method.");
    }
}

class Square implements Shape {
    @Override
    public void draw()
    {
        System.out.println("Inside Square::draw() method.");
    }
}

interface shapeFactory {
    Shape createShape();
}

class CircleFactory implements shapeFactory {
    @Override
    public Shape createShape()
    {
        return new Circle();
    }
}

class SquareFactory implements shapeFactory {
    @Override
    public Shape createShape()
    {
        return new Square();
    }
}

public class MethodFactory {
    public static void main(String[] args) {
        CircleFactory circleFactory = new CircleFactory();
        Shape shape = circleFactory.createShape();
        shape.draw();

        SquareFactory squareFactory = new SquareFactory();
        Shape shape2 = squareFactory.createShape();
        shape2.draw();
    }
}
